package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 此类专门用于发送MQ消息
 */
@Component
public class MQMovementManager {
    //针对动态的操作
    public static final Integer MOVEMENT_PUBLISH = 1;// 发动态
    public static final Integer MOVEMENT_BROWSE = 2;// 浏览动态
    public static final Integer MOVEMENT_LIKE = 3;// 点赞
    public static final Integer MOVEMENT_LOVE = 4;// 喜欢
    public static final Integer MOVEMENT_COMMENT = 5;// 评论
    public static final Integer MOVEMENT_DISLIKE = 6;// 取消点赞
    public static final Integer MOVEMENT_DISLOVE = 7;// 取消喜欢
    @Reference
    private MovementService movementService;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    //谁对什么内容进行什么操作  String movementId 参数有误(大数据不支持) 需要使用pid vid 数字类型
    public void sendMsg(String movementId , Integer type){
        Long loginUser = UserHolder.getId();//谁
        Movement movement = movementService.findMovementById(movementId);//哪个内容
        Map map = new HashMap<>();
        map.put("uid" ,loginUser ); //谁
        map.put("pid" ,movement.getPid() );//哪个内容
        map.put("type" ,type );//什么操作
        rocketMQTemplate.convertAndSend("tanhua-recommend-movement" ,map);
    }
}
